﻿using System.Text;
using Tilver.Coder.Core;
using Tilver.Coder.Utility;

namespace Tilver.Coder.Engine
{
    internal class EnumEngine : EngineBase
    {
        public CoderEnum  Enum { get; set; }

        public override string RenderToString()
        {
            var response = new StringBuilder();
            ResponseEnum(response, Tabs);
            return response.ToString();
        }

        private void ResponseEnum(StringBuilder reponse, int tabs)
        {
            reponse.AppendLine(ExtensionUtil.GetCoderSummary(tabs, Enum.Description));
            reponse.AppendFormatLine(tabs, "public enum {0} : {1}", Enum.CodeName, Enum.CSharpType);
            reponse.AppendTabLine(tabs, "{");

            foreach (var item in Enum.Items)
            {
                reponse.AppendLine(ExtensionUtil.GetCoderSummary(tabs + 1, item.Description));
                reponse.AppendFormatLine(tabs + 1,
                    "{0}{1},",
                    item.CodeName,
                    string.IsNullOrEmpty(item.Value) ? string.Empty : " = " + item.Value);
                reponse.AppendLine();
            }
            reponse.AppendTabLine(tabs, "}");
        }
    }
}
